]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Dynamically adjust spacing based on columnLimit
authorAdel Gadllah <adel.gadllah@gmail.com>
Tue, 19 Feb 2013 23:38:11 +0000 (00:38 +0100)
committerAdel Gadllah <adel.gadllah@gmail.com>
Tue, 19 Feb 2013 23:39:18 +0000 (00:39 +0100)
Adjust the spacing based on the available width when a columnLimit
is set to evenly place the icons.

https://bugzilla.gnome.org/show_bug.cgi?id=694215

js/ui/appDisplay.js
js/ui/iconGrid.js

index ecc2cb170a22107568875fc55c74b5841c68a09c..c38e328b0f7bee7edcb4511ed1e4c30a382840c6 100644 (file)
@@ -63,6 +63,9 @@ const AlphabeticalView = new Lang.Class({
         this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
                                              columnLimit: MAX_COLUMNS });
 
+        // Standard hack for ClutterBinLayout
+        this._grid.actor.x_expand = true;
+
         this._items = {};
         this._allItems = [];
     },
index 2b63865315d439a63d520cfeb2b6f7c2dba0b93b..98e57613b5b0c37f1a1bb040df8685d8e6922aa9 100644 (file)
@@ -241,7 +241,7 @@ const IconGrid = new Lang.Class({
         let availWidth = box.x2 - box.x1;
         let availHeight = box.y2 - box.y1;
 
-        let [nColumns, usedWidth] = this._computeLayout(availWidth);
+        let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
 
         let leftPadding;
         switch(this._xAlign) {
@@ -294,10 +294,10 @@ const IconGrid = new Lang.Class({
             }
 
             if (columnIndex == 0) {
-                y += this._vItemSize + this._spacing;
+                y += this._vItemSize + spacing;
                 x = box.x1 + leftPadding;
             } else {
-                x += this._hItemSize + this._spacing;
+                x += this._hItemSize + spacing;
             }
         }
     },
@@ -313,16 +313,25 @@ const IconGrid = new Lang.Class({
     _computeLayout: function (forWidth) {
         let nColumns = 0;
         let usedWidth = 0;
+        let spacing = this._spacing;
+
+        if (this._colLimit) {
+            let itemWidth = this._hItemSize * this._colLimit;
+            let emptyArea = forWidth - itemWidth;
+            spacing = Math.max(this._spacing, emptyArea / (2 * this._colLimit));
+            spacing = Math.round(spacing);
+        }
+
         while ((this._colLimit == null || nColumns < this._colLimit) &&
                (usedWidth + this._hItemSize <= forWidth)) {
-            usedWidth += this._hItemSize + this._spacing;
+            usedWidth += this._hItemSize + spacing;
             nColumns += 1;
         }
 
         if (nColumns > 0)
-            usedWidth -= this._spacing;
+            usedWidth -= spacing;
 
-        return [nColumns, usedWidth];
+        return [nColumns, usedWidth, spacing];
     },
 
     _onStyleChanged: function() {